<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>内容管理</el-breadcrumb-item>
        <el-breadcrumb-item>热门标签管理</el-breadcrumb-item> 
      </el-breadcrumb>
    </basic-container> 
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
        @row-update="rowUpdate"
      >
      
        <template slot="myTags" slot-scope="scope">
          <span v-for="item in scope.row.hot_tags.toString().split(',')" :key="item">
            <el-tag v-text="item"></el-tag>&nbsp;
          </span> 
        </template>
        <template slot="menuRight">
          <el-tag>数据共{{ data[0]!=undefined?data[0].hot_tags.toString().split(',').length:'0' }}条</el-tag>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script> 
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { catHotTags as baseURL } from "@/api/cat/baseUrls"; 
export default {
  data() {
    return {
      page: {
        // total: 0,
        // pageSize: 10,
        // pageSizes:[1,2,3]
      },
      type: true,
      data: [],
      params: {},
      form: {},
      option: {
        delBtn: false,
        addBtn:false,
        editBtn: true,
        searchBtn: true,
        tip: true,
        column: [
          {
            label:"热门标签",
            prop:'myTags',
            slot:true,
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
          },
          {
            label: "热门标签",
            prop: "hot_tags",
            type: "textarea",
            placeholder: "逗号拼接",
            hide:true,
            tip: "热门标签,请用英文逗号隔开每个热门标签",
            rules: [
              {
                required: true,
                message: "热门标签必须填写",
              },
            ],
          },

          {
            label: "最后操作信息",
            prop: "edit_time",
            type: "date",
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
            readonly: true,
          },
        ],
      },
    };
  },
  methods: {
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(baseURL.getTags,null,null,"GET");
      // this.page = response.page;
      this.data = response.data;
      this.loading = false;
    },
    /**修改 */
    async rowUpdate(row, index, done, loading) {
      let userInfo = this.$store.state.user.userInfo;
      row.edit_account_name = userInfo.username;
      row.edit_time = new Date();
      let data = await common(baseURL.update, row, null, "POST");
      if (data == null) {
        loading();
        return;
      }
      this.getList();
      done();
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },
    /**搜索 */
    searchChange(params, done) {
      
      this.params = params;
      // this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
  },
};
</script>